﻿using System.Diagnostics.Contracts;

namespace Leek.Persistence
{
    public sealed class DomainObjectId<T, TId>
        where T : DomainObject<T, TId>
    {
        private readonly DomainContext _context;
        private readonly TId _value;


        public DomainContext Context
        {
            [Pure]
            get { return _context; }
        }

        public TId Value
        {
            [Pure]
            get { return _value; }
        }


        internal DomainObjectId(DomainContext context, TId value)
        {
            _context = context;
            _value = value;
        }


        public override bool Equals(object obj)
        {
            var other = obj as DomainObjectId<T, TId>;
            if (other == null)
                return false;
            else
                return Value.Equals(other.Value);
        }

        public override int GetHashCode()
        {
            return Value.GetHashCode();
        }

        public override string ToString()
        {
            return Value.ToString();
        }
    }
}
